from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QTabWidget, QLabel, QHBoxLayout, QVBoxLayout, QWidget, QFrame

from bank_manage_system.gui.admi.card_tab import PRIMARY_COLOR, CardTab
from bank_manage_system.gui.admi.card_tab import apply_stylesheet, HEADER_FONT, DANGER_COLOR, DARKEN, BG_COLOR
from bank_manage_system.gui.admi.customer_tab import CustomerTab
from bank_manage_system.gui.admi.report_tab import ReportTab
from bank_manage_system.gui.admi.transaction_tab import TransactionTab


class AdminDashboard(QWidget):
    """管理员主界面"""

    def __init__(self, db, user_id):
        super().__init__()
        self.db = db
        self.user_id = user_id
        self.styles = apply_stylesheet(self)
        self.initUI()

    def initUI(self):
        # 主布局
        main_layout = QVBoxLayout(self)
        main_layout.setContentsMargins(20, 15, 20, 20)
        main_layout.setSpacing(15)

        # 标题栏
        header_layout = QHBoxLayout()
        header_layout.setContentsMargins(0, 0, 0, 0)

        # 系统标题
        title_label = QLabel("银行管理系统 - 管理员面板")
        title_label.setFont(QFont("Microsoft YaHei UI", 16, QFont.Bold))
        title_label.setStyleSheet(f"color: {PRIMARY_COLOR};")
        header_layout.addWidget(title_label, 0, Qt.AlignLeft)

        # 管理员信息
        admin_info_layout = QHBoxLayout()
        admin_label = QLabel("管理员 ID:")
        admin_label.setFont(HEADER_FONT)
        admin_id_label = QLabel(f"{self.user_id}")
        admin_id_label.setFont(QFont("Microsoft YaHei UI", 12, QFont.Bold))
        admin_id_label.setStyleSheet(
            f"color: {DANGER_COLOR}; background-color: rgba(231, 76, 60, 30); padding: 5px; border-radius: 4px;")

        admin_info_layout.addWidget(admin_label)
        admin_info_layout.addWidget(admin_id_label)
        header_layout.addLayout(admin_info_layout)

        main_layout.addLayout(header_layout)

        # 分隔线
        separator = QFrame()
        separator.setFrameShape(QFrame.HLine)
        separator.setFrameShadow(QFrame.Sunken)
        separator.setStyleSheet(f"background-color: {DARKEN(BG_COLOR, 15)};")
        separator.setFixedHeight(2)
        main_layout.addWidget(separator)

        # 选项卡
        self.tab_widget = QTabWidget()
        self.tab_widget.setFont(HEADER_FONT)

        # 银行卡管理
        self.card_tab = CardTab(self.db)
        self.tab_widget.addTab(self.card_tab, "银行卡管理")

        # 客户管理
        self.customer_tab = CustomerTab(self.db)
        self.tab_widget.addTab(self.customer_tab, "客户管理")

        # 交易管理
        self.transaction_tab = TransactionTab(self.db)
        self.tab_widget.addTab(self.transaction_tab, "交易管理")

        # 报表管理
        self.report_tab = ReportTab(self.db)
        self.tab_widget.addTab(self.report_tab, "报表管理")

        main_layout.addWidget(self.tab_widget)

        # 设置窗口属性
        self.setWindowTitle("银行管理系统 - 管理员面板")
        self.resize(1200, 800)
        self.setStyleSheet(self.styles["global"])